package com.sensetime.jv.util;

import com.sensetime.jv.entity.LoginUser;
import com.sensetime.jv.exception.CustomException;

public class UserInfoUtils {


    private static final ThreadLocal<LoginUser>  userInfoThreadLocal = new ThreadLocal<>();


    public static LoginUser getUserInfo(){
        LoginUser loginUser = userInfoThreadLocal.get();
        if (loginUser == null){
            throw new CustomException("认证已过期，请重新登录后重试");
        }
        return loginUser;
    }


    public static void cacheUserInfo(LoginUser loginUser){
        userInfoThreadLocal.set(loginUser);
    }

    public static void clearUserInfo() {
        userInfoThreadLocal.remove();
    }

}
